package com.example.automanagement.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.automanagement.dto.BillDto;
import com.example.automanagement.entity.Bill;
import com.example.automanagement.service.BillService;
import com.example.automanagement.util.PageBean;
import com.example.automanagement.util.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BillController {
    @Resource
    private BillService billService;

    @GetMapping("/billPageQuery")
    public Result billPageQuery(@RequestParam("userId") String userId){
        List<Bill> bills = billService.pageList(userId);
        List<BillDto> billDtoList = BeanUtil.copyToList(bills, BillDto.class);
        return Result.success(billDtoList);
    }
    @PostMapping("/createBill")
    public Result createBill(@RequestBody Bill bill){
        if(bill == null)
            return Result.error("500","请检查输入");

        billService.addBill(bill);
        return Result.success("成功");
    }
    //根据id获取报账详情
    @GetMapping("/getBillById")
    public Result getBillById(@RequestParam("billId") String billId){
        if(billId == null)
            return Result.error("500","请检查输入");
        Bill bill = billService.getBillById(billId);
        return Result.success(bill);
    }
}
